import { useRouter } from 'vue-router'
import {
  getActionPlansPatientsDetails,
  getActionPlansDetails,
  getActionPlansByDoctorIdDetails,
  getAllActionPlansDetails,
  getAllMarkedListDetails,
  getAllMedicalRecordsByDoctorIdDetails,
  getAllSubmitRecordsDetails,
  getAllTreatRecordsDetails,
  getAllUnmarkedList,
  getAsthmaControlListDetails,
  getAsthmaDiagnosisListDetails,
  getBreathSoundListDetails,
  getDrugWithdrawalPatientsDetails,
  getExistDiagnosisPatientsDetails,
  getMedicalRecordsByDoctorIdDetails,
  getNewPatientsDetails,
  getNewPatientsByDoctorIdDetails,
  getNewTreatRecords,
  getPatientPefListDetails,
  getPatientsByAgeRangeDetails,
  getPatientsByAsthmaTriggersDetails,
  getPrescriptionListDetails,
  getRemoteRecordsDetails,
  getReturnVisitPatientsDetails,
  getSubmitRecordsDetails,
  getTreatRecordsDetails,
  getTreatmentLevelListDetails,
  getMarkedPatientsDetails,
  getDiagnosedPatientsDetails,
  getMarkedByLevel,
} from '@/api/modules/statistics'
export function useChartDetails() {
  function checkApi(
    title: String,
    params: {
      pageIndex: number
      pageSize: number
      startDay: String
      endDay: String
      doctorId?: string
      diagnosis?: string
      triggers?: string
      level?: string
    }
  ) {
    console.log('checkApi =' + title)
    const {
      pageIndex,
      pageSize,
      startDay,
      endDay,
      doctorId = '',
      diagnosis = '',
      triggers = '',
      level = '',
    } = params
    if (title === '行动计划制定人数') {
      return getActionPlansPatientsDetails({
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '行动计划制定总数') {
      return getActionPlansDetails({ pageIndex, pageSize, startDay, endDay })
    } else if (title === '行动计划数') {
      const doctorIdInt = parseInt(doctorId)
      return getActionPlansByDoctorIdDetails({
        pageIndex,
        pageSize,
        startDay,
        endDay,
        doctorId: doctorIdInt,
      })
    } else if (title === '累计行动计划制定总数') {
      return getAllActionPlansDetails({ pageIndex, pageSize, startDay, endDay })
    } else if (title === '累计打卡率' || title === '累计打卡列表') {
      return getAllMarkedListDetails({ pageIndex, pageSize, startDay, endDay })
    } else if (title === '新增病历总数') {
      // 院内人员-新增病历总数列表
      const doctorIdInt = parseInt(doctorId)
      return getAllMedicalRecordsByDoctorIdDetails({
        pageIndex,
        pageSize,
        startDay,
        endDay,
        doctorId: doctorIdInt,
      })
    } else if (title === '累计提交病历数') {
      return getAllSubmitRecordsDetails({ pageIndex, pageSize, submit: 2 })
    } else if (title === '累计未提交病历数') {
      return getAllSubmitRecordsDetails({ pageIndex, pageSize, submit: 1 })
    } else if (title === '累计病历总数') {
      return getAllTreatRecordsDetails({ pageIndex, pageSize })
    } else if (title === '累计未打卡率' || title === '累计未打卡列表') {
      return getAllUnmarkedList({ pageIndex, pageSize })
    } else if (title === '哮喘评估控制次数') {
      return getAsthmaControlListDetails({
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '诊断统计') {
      const diagnosisInt = parseInt(diagnosis)
      return getAsthmaDiagnosisListDetails({
        pageIndex,
        pageSize,
        startDay,
        endDay,
        diagnosis: diagnosisInt,
      })
    } else if (title === '呼吸音采集数') {
      return getBreathSoundListDetails({
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '累计确诊人数') {
      return getDiagnosedPatientsDetails({ pageIndex, pageSize })
    } else if (title === '累计停药人数') {
      return getDrugWithdrawalPatientsDetails({ pageIndex, pageSize })
    } else if (title === '累计管理患者') {
      return getExistDiagnosisPatientsDetails({ pageIndex, pageSize })
    } else if (title === '打卡数') {
      return getMarkedPatientsDetails({ pageIndex, pageSize, startDay, endDay })
    } else if (title === '首诊病历总数') {
      const doctorIdInt = parseInt(doctorId)
      return getMedicalRecordsByDoctorIdDetails({
        pageIndex,
        pageSize,
        startDay,
        endDay,
        treatmentType: 1,
        doctorId: doctorIdInt,
      })
    } else if (title === '复诊病历总数') {
      const doctorIdInt = parseInt(doctorId)
      return getMedicalRecordsByDoctorIdDetails({
        pageIndex,
        pageSize,
        startDay,
        endDay,
        treatmentType: 0,
        doctorId: doctorIdInt,
      })
    } else if (title === '新增患者数') {
      return getNewPatientsDetails({ pageIndex, pageSize, startDay, endDay })
    } else if (title === '患者数') {
      const doctorIdInt = parseInt(doctorId)
      return getNewPatientsByDoctorIdDetails({
        pageIndex,
        pageSize,
        startDay,
        endDay,
        doctorId: doctorIdInt,
      })
    } else if (title === '新增首诊病历数') {
      return getNewTreatRecords({
        pageIndex,
        pageSize,
        startDay,
        endDay,
        treatmentType: 1,
      })
    } else if (title === '新增复诊病历数') {
      return getNewTreatRecords({
        pageIndex,
        pageSize,
        startDay,
        endDay,
        treatmentType: 0,
      })
    } else if (title === '呼气峰流速上传数') {
      return getPatientPefListDetails({ pageIndex, pageSize, startDay, endDay })
    } else if (title === '12岁≤x') {
      return getPatientsByAgeRangeDetails({
        ageRange: 2,
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === 'x<6岁') {
      return getPatientsByAgeRangeDetails({
        ageRange: 0,
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '6岁≤x<12岁') {
      return getPatientsByAgeRangeDetails({
        ageRange: 1,
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '哮喘诱因列表') {
      const triggersInt = parseInt(triggers)
      return getPatientsByAsthmaTriggersDetails({
        triggers: triggersInt,
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '开方数') {
      const doctorIdInt = parseInt(doctorId)
      return getPrescriptionListDetails({
        doctorId: doctorIdInt,
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '远程复诊数') {
      return getRemoteRecordsDetails({
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '累计复诊率') {
      return getReturnVisitPatientsDetails({
        pageIndex,
        pageSize,
      })
    } else if (title === '提交病历数') {
      return getSubmitRecordsDetails({
        submit: 2,
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '未提交病历数') {
      return getSubmitRecordsDetails({
        submit: 1,
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '累计首诊病历总数') {
      return getTreatRecordsDetails({
        treatmentType: 1,
        pageIndex,
        pageSize,
      })
    } else if (title === '累计复诊病历总数') {
      return getTreatRecordsDetails({
        treatmentType: 0,
        pageIndex,
        pageSize,
      })
    } else if (title === '治疗级别') {
      const levelInt = parseInt(level)
      return getTreatmentLevelListDetails({
        level: levelInt,
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '红区打卡') {
      return getMarkedByLevel({
        critical: 3,
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '黄区打卡') {
      return getMarkedByLevel({
        critical: 2,
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else if (title === '绿区打卡') {
      return getMarkedByLevel({
        critical: 1,
        pageIndex,
        pageSize,
        startDay,
        endDay,
      })
    } else {
      window.alert('该项未有，请通知客服')
    }
  }
  return { checkApi }
}
